display("conf[PUBLIC_STATUS]"); // 需要翻译的类型
$(function() {
    $('#verifierEditDialog').dialog({
        buttons:[{text:'保存',handler:function(){
            if(!$('#verifierEditForm').form('validate')){return;}
            $('#verifierEditForm')._ajaxForm(function(r){
                if(r.r){
                	$('#verifierEditDialog').dialog('close');
                	$('#grid').datagrid('reload');
                }else{
                	$.messager.alert('操作提示', r.m,'error');
                }
            });
        }},{text:'关闭',handler:function(){$('#verifierEditDialog').dialog('close');}}]
    });
    var grid = $('#grid')._datagrid({
        checkOnSelect:false,
        selectOnCheck:false,
        toolbar : [{
            text : '添加',
            iconCls : 'icon-add',
            handler : handler_add
        }, '-' ]
    });
    $('#queryButton').click(function(){
        var params = $('#queryForm')._formToJson();
        $(grid).datagrid('load',params);
    });
});
var formatter = {
    status : function(value, rowData, rowIndex) {
    	return value != null ? $.fn.display.conf.PUBLIC_STATUS[value] : value;
    },
    opt : function(value, rowData, rowIndex) {
       var html = '<a class="spacing a-blue" onclick="upd('+rowIndex+');" href="javascript:void(0);">修改</a>';
       html+= '<a class="spacing a-red"  onclick="del('+rowIndex+');" href="javascript:void(0);">删除</a>';
       return html;
    }
};
/*新增*/
function handler_add() {
    $('#verifierEditForm').attr('action','verifier/add.html').resetForm();
	$("#id").val('');
    $('#verifierEditDialog').dialog('open').dialog("setTitle","新增授权人");
}
/*修改*/
function upd(rowIndex) {
    $('#verifierEditForm').attr('action','verifier/upd.html').resetForm();
    var data = $('#grid').datagrid('getRows')[rowIndex];
    $("#userId").val(data.userId);
    $('#verifierEditForm')._jsonToForm(data);
    $('#verifierEditDialog').dialog('open').dialog('setTitle','修改授权人');
}
/*删除*/
function del(rowIndex) {
	var data = $('#grid').datagrid('getRows')[rowIndex];
	if(data.status==0){
	    $.messager.confirm('操作提示', '确定要删除该授权人吗？', function(r){
	        if (r){
	            $._ajaxPost('verifier/del.html',{id:data.id}, function(r){
	                if(r.r){$('#grid').datagrid('reload');}else{$.messager.alert('操作提示', r.m,'error');}
	            });
	        }
	    });
	}else{
		asyncbox.tips('启用状态下不能删除！');
	}
}
$(function(){
	//username绑定事件获得phone
    $('#username').change(function() {
    	var username = $("#username").val();
    	var id = $("#id").val();
		if (username == "" || username == null) {
			$("#phone").val('');
			$('#userId').val('');
			return;
		}
		$._ajaxPost('verifier/changeName.html',{username : username,id : id}, function(r) {
			if (r.r) {
				$('#phone').val(r.allNames[0].phone);
				$('#userId').val(r.allNames[0].userId);						
			} else {
				 asyncbox.tips(r.m, r.r ? 'success' : 'error');
				$("#username").val('');
				$('#username')._pullDownList('refresh');
			}
		});
    });
}); 
